[...slug].md.ts 453 B

123456789101112131415161718
  1. import type { APIRoute } from "astro"
  2. import { getCollection } from "astro:content"
  3. export const GET: APIRoute = async ({ params }) => {
  4. const slug = params.slug || "index"
  5. const docs = await getCollection("docs")
  6. const doc = docs.find((d) => d.id === slug)
  7. if (!doc) {
  8. return new Response("Not found", { status: 404 })
  9. }
  10. return new Response(doc.body, {
  11. headers: {
  12. "Content-Type": "text/plain; charset=utf-8",
  13. },
  14. })
  15. }